# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time        : 2020/11/21 15:02
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : first_bc_spline_interpolation.py
@Version     : Version 1.0.0
@Description : TODO 调用第三方库实现三次样条(第一边界条件)插值
@Created By  : PyCharm
"""
import numpy as np
from scipy.interpolate import CubicSpline
import matplotlib.pyplot as plt
import pylab as pl


def draw(x_range, y_range):
    # 绘制真值函数图形
    plt.plot(x_range, y_range, label='平方根真值函数', color='green')
    # 绘制指定三次样条插值函数横坐标范围内的图形
    plt.plot(x_range, ploy(x_range), label='样条插值函数S(x)', color='red')
    plt.title("三次样条插值第一边界条件S(x)")
    pl.rcParams['font.sans-serif'] = ['SimHei']
    pl.rcParams['axes.unicode_minus'] = False
    plt.legend(loc="lower right")
    plt.show()


if __name__ == '__main__':
    # 9个已知插值结点
    x = np.array([i ** 2 for i in range(9)])
    y = np.arange(9)
    plt.scatter(x, y, label='插值点', color='blue')
    ploy = CubicSpline(x, y, bc_type='clamped')
    # 三次样条插值函数横坐标范围
    range_x = np.linspace(0, 64, 100)
    # 真值函数
    range_y = pow(range_x, 0.5)
    draw(range_x, range_y)
